//
//  WKFriendInforHeadView.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/20.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKFriendInforHeadView.h"

@interface WKFriendInforHeadView ()
@property(nonatomic,strong)UIImageView *headerImgView;
@property(nonatomic,strong)UILabel *nameLb;
@property(nonatomic,strong)UILabel *informationLb;
@property(nonatomic,strong)UIButton *guanzunBtn;

@property(nonatomic,strong)UIButton *gzNumBtn;
@property(nonatomic,strong)UIButton *fansNumBtn;
@property(nonatomic,strong)UIButton *zanNumBtn;

@property(nonatomic,strong)UILabel *gzLb,*fansLb,*zanLb;
@property(nonatomic,strong)UILabel *gzTitlLb,*fansTitleLb,*zanTitleLb;
@end

@implementation WKFriendInforHeadView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self ==[super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    
    UIImageView *bgimgView = [[UIImageView alloc]init];
    bgimgView.userInteractionEnabled = YES;
    bgimgView.backgroundColor = BACK_COLOR;
    [self addSubview:bgimgView];
    [bgimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
    
    [bgimgView addSubview:self.headerImgView];
    [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(NavBarHeight+16);
        make.size.mas_equalTo(CGSizeMake(48, 48));
    }];
    
    [bgimgView addSubview:self.nameLb];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerImgView.mas_right).offset(10);
        make.top.mas_equalTo(self.headerImgView.mas_top).offset(9);
        make.size.mas_equalTo(CGSizeMake(150, 15));
    }];
    
    [bgimgView addSubview:self.informationLb];
    [self.informationLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLb.mas_left);
        make.top.mas_equalTo(self.nameLb.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(150, 11));
    }];
    
    [bgimgView addSubview:self.guanzunBtn];
    [self.guanzunBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(self.nameLb.mas_top);
        make.size.mas_equalTo(CGSizeMake(50, 24));
    }];
    
    [_guanzunBtn setTitle:@"+关注" forState:UIControlStateNormal];
    [_guanzunBtn setTitle:@"已关注" forState:UIControlStateSelected];
    [_guanzunBtn setTitleColor:UIColorFromHex(0xFFFFFF) forState:UIControlStateNormal];
    [_guanzunBtn setTitleColor:UIColorFromHex(0xF54050) forState:UIControlStateSelected];
    _guanzunBtn.layer.cornerRadius  = 5;
    _guanzunBtn.layer.masksToBounds = YES;
    _guanzunBtn.layer.borderWidth = 1;
    _guanzunBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    _guanzunBtn.titleLabel.font = PFSC_RegularFont(11);
    [_guanzunBtn addTarget:self action:@selector(guanzhuAction:) forControlEvents:UIControlEventTouchUpInside];
    
     CGFloat lable_width = (ScreenWidth - 140-2)/3;
    
    [bgimgView addSubview:self.gzLb];
    [self.gzLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLb.mas_left);
        make.top.mas_equalTo(self.headerImgView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
    }];
    
    [bgimgView addSubview:self.fansLb];
    [self.fansLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzLb.mas_top);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
        make.centerX.mas_equalTo(bgimgView.mas_centerX);
    }];
    
    [bgimgView addSubview:self.zanLb];
    [self.zanLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-70);
        make.top.mas_equalTo(self.gzLb.mas_top);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
    }];
    
    [bgimgView addSubview:self.gzTitlLb];
    [self.gzTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLb.mas_left);
        make.top.mas_equalTo(self.gzLb.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
    }];
    
    [bgimgView addSubview:self.fansTitleLb];
    [self.fansTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzTitlLb.mas_top);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
        make.centerX.mas_equalTo(bgimgView.mas_centerX);
    }];
    
    [bgimgView addSubview:self.zanTitleLb];
    [self.zanTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-70);
        make.top.mas_equalTo(self.gzTitlLb.mas_top);
        make.size.mas_equalTo(CGSizeMake(lable_width, 15));
    }];
    
    
    
    [bgimgView addSubview:self.gzNumBtn];
    [self.gzNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLb.mas_left);
        make.top.mas_equalTo(self.headerImgView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(lable_width, 40));
    }];
    
    [bgimgView addSubview:self.fansNumBtn];
    [self.fansNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzNumBtn.mas_top);
        make.size.mas_equalTo(CGSizeMake(lable_width, 40));
        make.centerX.mas_equalTo(bgimgView.mas_centerX);
    }];
    
    [bgimgView addSubview:self.zanNumBtn];
    [self.zanNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-70);
        make.top.mas_equalTo(self.headerImgView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(lable_width, 40));
    }];
    
    _gzNumBtn.tag = 900;
    _fansNumBtn.tag = 901;
    _zanNumBtn.tag = 902;
    
    [self.zanNumBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.fansNumBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.gzNumBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
   
    
    UIView *line1 = [[UIView alloc]init];
    line1.backgroundColor = [UIColor whiteColor];
    [bgimgView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzLb.mas_top).offset(8);
        make.left.mas_equalTo(self.gzLb.mas_right);
        make.size.mas_equalTo(CGSizeMake(1, 15));
    }];
    
    UIView *line2 = [[UIView alloc]init];
    line2.backgroundColor = [UIColor whiteColor];
    [bgimgView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzLb.mas_top).offset(8);
        make.left.mas_equalTo(self.fansLb.mas_right);
        make.size.mas_equalTo(CGSizeMake(1, 15));
    }];
    
    
    _gzTitlLb.text = @"关注";
    _fansTitleLb.text = @"粉丝";
    _zanTitleLb.text = @"获赞";
    
    
    
    
    
    [_headerImgView sd_setImageWithURL:[NSURL URLWithString:@"http://b-ssl.duitang.com/uploads/item/201410/04/20141004162939_VERQc.jpeg"]];
    _headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    _headerImgView.layer.masksToBounds = YES;
    _headerImgView.layer.cornerRadius = 48/2;
    
    _nameLb.text = @"一直爱睡觉的猫";
    _informationLb.text = @"北京市 | 25岁 | 女";
    
//    _gzNumBtn.backgroundColor = [UIColor yellowColor];
//    _fansNumBtn.backgroundColor = [UIColor yellowColor];
//    _zanNumBtn.backgroundColor = [UIColor yellowColor];
    
    _zanLb.text = @"26";
    _fansLb.text = @"232";
    _gzLb.text = @"1234";
    
}

#pragma mark - button点击事件
- (void)btnClick:(UIButton*)sender{
    NSInteger index = sender.tag - 900;
    if (self.block) {
        self.block(index);
    }
}

#pragma mark - 点击关注
- (void)guanzhuAction:(UIButton*)sender{
    sender.selected = !sender.selected;
    _guanzunBtn.backgroundColor = sender.selected == YES ?  [UIColor whiteColor] : UIColorFromHex(0xF54050);
}

- (UIImageView*)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]init];
    }
    return _headerImgView;
}

- (UILabel*)nameLb{
    if (!_nameLb) {
        _nameLb = [[UILabel alloc]init];
        _nameLb.textColor = [UIColor whiteColor];
        _nameLb.font = PFSC_BoldFont(15);
    }
    return _nameLb;
}

- (UILabel*)informationLb{
    if (!_informationLb) {
        _informationLb = [[UILabel alloc]init];
        _informationLb.textColor = [UIColor whiteColor];
        _informationLb.font = PFSC_BoldFont(11);
    }
    return _informationLb;
}

- (UIButton*)guanzunBtn{
    if (!_guanzunBtn) {
        _guanzunBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _guanzunBtn;
}

- (UILabel*)gzLb{
    if (!_gzLb) {
        _gzLb = [[UILabel alloc]init];
        _gzLb.textColor = [UIColor whiteColor];
        _gzLb.font = PFSC_MediumFont(12);
        _gzLb.textAlignment = NSTextAlignmentLeft;
    }
    return _gzLb;
}

- (UILabel*)fansLb{
    if (!_fansLb) {
        _fansLb = [[UILabel alloc]init];
        _fansLb.textColor = [UIColor whiteColor];
        _fansLb.font = PFSC_MediumFont(12);
        _fansLb.textAlignment = NSTextAlignmentCenter;
    }
    return _fansLb;
}

- (UILabel*)zanLb{
    if (!_zanLb) {
        _zanLb = [[UILabel alloc]init];
        _zanLb.textColor = [UIColor whiteColor];
        _zanLb.font = PFSC_MediumFont(12);
        _zanLb.textAlignment = NSTextAlignmentRight;
    }
    return _zanLb;
}

- (UILabel*)gzTitlLb{
    if (!_gzTitlLb) {
        _gzTitlLb = [[UILabel alloc]init];
        _gzTitlLb.textColor = [UIColor whiteColor];
        _gzTitlLb.font = PFSC_MediumFont(12);
        _gzTitlLb.textAlignment = NSTextAlignmentLeft;
    }
    return _gzTitlLb;
}

- (UILabel*)fansTitleLb{
    if (!_fansTitleLb) {
        _fansTitleLb = [[UILabel alloc]init];
        _fansTitleLb.textColor = [UIColor whiteColor];
        _fansTitleLb.font = PFSC_MediumFont(12);
        _fansTitleLb.textAlignment = NSTextAlignmentCenter;
    }
    return _fansTitleLb;
}

- (UILabel*)zanTitleLb{
    if (!_zanTitleLb) {
        _zanTitleLb = [[UILabel alloc]init];
        _zanTitleLb.textColor = [UIColor whiteColor];
        _zanTitleLb.font = PFSC_MediumFont(12);
        _zanTitleLb.textAlignment = NSTextAlignmentRight;
    }
    return _zanTitleLb;
}


- (UIButton*)gzNumBtn{
    if (!_gzNumBtn) {
        _gzNumBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    }
    return _gzNumBtn;
}

- (UIButton*)fansNumBtn{
    if (!_fansNumBtn) {
        _fansNumBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
    }
    return _fansNumBtn;
}

- (UIButton*)zanNumBtn{
    if (!_zanNumBtn) {
        _zanNumBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    }
    return _zanNumBtn;
}


@end
